
//添加
function save(){
	var student_number=$(".student_number").val();
	var password=$(".password").val();
	var nick_name=$(".nick_name").val();
	var real_name=$(".real_name").val();

	//学号验证
	if(student_number==null){
		$("body").overhang({
			type: "error",
			message: "学号没有填写！"
		});
		return null;
	}
	if(student_number==""){
		$("body").overhang({
			type: "error",
			message: "学号没有填写！"
		});
		return null;
	}
	student_number=student_number.toUpperCase();
	var flag=student_number.indexOf("P1");
	if(flag==-1){
		$("body").overhang({
			type: "error",
			message: "学号填写错误！"
		});
		return null;
	}
	var len=student_number.length;
	if(len!=10){
		$("body").overhang({
			type: "error",
			message: "学号填写错误！"
		});
		return null;
	}


	//密码验证
	if(password==null){
		$("body").overhang({
			type: "error",
			message: "密码没有填写！"
		});
		return null;
	}
	if(password==""){
		$("body").overhang({
			type: "error",
			message: "密码没有填写！"
		});
		return null;
	}
	len=password.length;
	if(len<6 || len>12){
		$("body").overhang({
			type: "error",
			message: "密码填写错误！"
		});
		return null;
	}


	//昵称
	if(nick_name==null){
		$("body").overhang({
			type: "error",
			message: "昵称没有填写！"
		});
		return null;
	}
	if(nick_name==""){
		$("body").overhang({
			type: "error",
			message: "昵称没有填写！"
		});
		return null;
	}

	//真实姓名
	if(real_name==null){
		$("body").overhang({
			type: "error",
			message: "真实姓名没有填写！"
		});
		return null;
	}
	if(real_name==""){
		$("body").overhang({
			type: "error",
			message: "真实姓名没有填写！"
		});
		return null;
	}



	var options = {
		url : ctx+"/core/admin/member/add.do",
		type : "POST",
		dataType : 'json',
		success : function(result) {				
		 	if(result.result==1){
		 		
		 		alert(result.message);
		 		
		 		location.reload();
		 		
		 	}else if(result.result==0){
		 		$("body").overhang({
					type: "error",
					message: result.message
				});
		 	}
		},
		error : function(e) {
			$("body").overhang({
	 			type: "error",
	 			message: "请求错误！请重试！"
	 		});
			
		}
	};
	$("#addForm").ajaxSubmit(options);
		
}



$(".student_number").blur(function(){
	var student_number=$(".student_number").val();

	if(student_number==null || student_number==""){
		$(".number_msg").css("display","block");
		$(".number_msg").text("学号没有填写！");
		return null;
	}
	
	student_number=student_number.toUpperCase();
	var flag=student_number.indexOf("P1");
	if(flag==-1){
		$(".number_msg").css("display","block");
		$(".number_msg").text("学号填写错误！");
		return null;
	}
	var len=student_number.length;
	if(len!=10){
		$(".number_msg").css("display","block");
		$(".number_msg").text("学号填写错误！");
		return null;
	}

	$(".number_msg").css("display","none");
	//检测学号是否可以注册
	$.ajax({
		url: ctx+"/api/member/check-student_number.do",
		data: {'student_number':student_number},
		type:"POST",
		dataType:"json",
		success:function(result){
			if(result.result==1){
				$(".number_success").css("display","block");
				$(".number_success").text(result.message);
			}else{
				$(".number_success").css("display","none");
				$(".number_msg").css("display","block");
				$(".number_msg").text(result.message);
			}
		},
		error:function(){
			$("body").overhang({
	 			type: "error",
	 			message: "请求错误！请重试！"
	 		});
		}
	});
	
});

$(".password").blur(function(){
	var password=$(".password").val();
	
	if(password==null || password==""){
		$(".password_msg").css("display","block");
		$(".password_msg").text("密码没有填写！");
		return null;
	}else{
		$(".password_msg").css("display","none");
	}

	len=password.length;
	if(len<6 || len>12){
		$(".password_msg").css("display","block");
		$(".password_msg").text("密码填写错误！");
		return null;
	}

	$(".password_msg").css("display","none");
	
});


$(".real_name").blur(function(){
	var real_name=$(".real_name").val();

	if(real_name==null || real_name==""){
		$(".real_name_msg").css("display","block");
		$(".real_name_msg").text("姓名没有填写！");
		return null;
	}

	$(".real_name_msg").css("display","none");

});

$(".nick_name").blur(function(){
	var nick_name=$(".nick_name").val();

	if(nick_name==null || nick_name==""){
		$(".nick_name_msg").css("display","block");
		$(".nick_name_msg").text("昵称没有填写！");
		return null;
	}

	$(".nick_name_msg").css("display","none");
	//检测昵称是否可以注册
	$.ajax({
		url: ctx+"/api/member/check-nick_name.do",
		data: {'nick_name':nick_name},
		type:"POST",
		dataType:"json",
		success:function(result){
			if(result.result==1){
				$(".nick_success").css("display","block");
				$(".nick_success").text(result.message);
			}else{
				$(".nick_success").css("display","none");
				$(".nick_name_msg").css("display","block");
				$(".nick_name_msg").text(result.message);
			}
		},
		error:function(){
			$("body").overhang({
	 			type: "error",
	 			message: "请求错误！请重试！"
	 		});
		}
	});
});

$(".phone").blur(function(){
	var tel=$(".phone").val();
	var reg = /^0?1[3|4|5|8][0-9]\d{8}$/;
	if (reg.test(tel)) {
		$(".phone_msg").css("display","none");
		$(".phone_success").css("display","block");
	  	$(".phone_msg").text("手机号码正确！");
	}else{
		$(".phone_msg").css("display","block");
		$(".phone_success").css("display","none");
	  	$(".phone_msg").text("手机号码错误！");
	}
});